"""
 encoding    : utf-8
 @File       : staff_add.py
 @Author     : qin
 @Version    :
 @Description:
 @Date       : 2024/07/10
"""
from auto_code.common.login import Login
import time
from auto_code.common.common_function import OperateMysql
import unittest

class StaffAdd(Login):
    def open_page_staff(self):
        #定位人员管理元素并点击
        self.driver.find_element('xpath','//*[@id="root"]/section/aside/div/ul/li[3]/div/span').click()
        #定位人员列表并点击
        self.driver.find_element('xpath','//*[@id="system$Menu"]/li/a').click()
    def open_add_page(self,**keyargs):
        #定位添加按钮并点击
        self.driver.find_element('xpath','//*[@id="root"]/section/section/main/div/div[1]/button[2]').click()
        #定位用户名按钮并输入数据
        self.driver.find_element('id','name').send_keys(keyargs['uname'])
        #定位账户并输入数据
        self.driver.find_element('id','account').send_keys(keyargs['account'])
        #定位密码并输入密码
        self.driver.find_element('id','pwd').send_keys(keyargs['pwd'])
        # time.sleep(5)
        #定位男女文本框并点击
        if len(keyargs['gender']) > 0:
            self.driver.find_element('xpath','//*[@id="sex"]/div/div/div').click()   # 性别
            time.sleep(1)
            options_list = self.driver.find_elements('xpath','/html/body/div[3]/div/div/div/ul/li')
            # print(options_list)
            for i in options_list:
                if i.text == keyargs['gender']:
                    i.click()
                    break

        if len(keyargs['company']) > 0:
            #定位绑定公司并点击
            self.driver.find_element('id','cityComId').click()
            time.sleep(1)
            options_list = self.driver.find_elements('xpath','/html/body/div[4]/div/div/div/ul[1]/li')

            for i in options_list:
                if i.text == keyargs['company']:
                    i.click()
                    time.sleep(1)
                    self.driver.find_element('xpath','/html/body/div[4]/div/div/div/ul[2]/li').click()
                    break

        if len(keyargs['job']) > 0:
            #定位职位元素并点击
            self.driver.find_element('xpath','//*[@id="roles"]/div/div/div').click()
            time.sleep(1)
            options_list = self.driver.find_elements('xpath','/html/body/div/div/div/div/ul/li')
            for i in options_list:
                if i.text == keyargs['job']:
                    i.click()
                    break
        if len(keyargs['address']) > 0:
            self.driver.find_element('xpath','//*[@id="cityId"]/div/div/div').click()
            time.sleep(1)
            options_list = self.driver.find_elements('xpath','/html/body/div/div/div/div/ul/li')
            for i in options_list:
                if i.text == keyargs['address']:
                    i.click()
                    break
        #定位电话并输入数据
        self.driver.find_element('id','phone').send_keys(keyargs['phone'])
        if len(keyargs['status']) > 0:
            self.driver.find_element('id','status').click()
            time.sleep(1)
            options_list = self.driver.find_elements('xpath','/html/body/div/div/div/div/ul/li')
            for i in options_list:
                if i.text == keyargs['status']:
                    i.click()
                    break
        #定位邮箱并输入数据
        self.driver.find_element('id','email').send_keys(keyargs['email'])
        if len(keyargs['product']) > 0:
            self.driver.find_element('xpath','//*[@id="productId"]/div/div/div').click()
            time.sleep(1)
            options_list = self.driver.find_elements('xpath','/html/body/div/div/div/div/ul/li')
            for i in options_list:
                if i.text == keyargs['product']:
                    i.click()
                    break
        if len(keyargs['partment']) > 0:
            self.driver.find_element('xpath','//*[@id="departmentId"]/div/div/div').click()
            time.sleep(1)
            options_list = self.driver.find_elements('xpath','/html/body/div/div/div/div/ul/li')
            for i in options_list:
                if i.text == keyargs['partment']:
                    i.click()
                    break
        # if keyargs['pwd'] and keyargs['test_mark'] == 0:
        #     #点击重置密码按钮
        #     self.driver.find_element('xpath','/html/body/div[2]/div/div[2]/div/div[2]/div[3]/div/button[1]').click()


    def reset_pwd(self):
        #定位重置密码按钮并点击
        self.driver.find_element('xpath','/html/body/div[2]/div/div[2]/div/div[2]/div[3]/div/button[1]').click()

    def submit(self):
        #定位提交按钮并点击
        self.driver.find_element('xpath','/html/body/div[2]/div/div[2]/div/div[2]/div[3]/div/button[2]').click()



    def submit_assert(self,mark_content):
        '''这个是用来反向断言的'''

        time.sleep(1)
        res_ele = self.driver.find_element('xpath',
                                           '/html/body/div[1]/section/section/main/div/div[2]/div/div/div/div/div/div/div/table/tbody/tr[1]/td[3]')
        # print(res_ele.text)
        mysql = OperateMysql('cloud')
        res_data = mysql.selectData(f'select username from user where username = {mark_content}')
        assert not (res_ele.text == mark_content and res_data), '测试失败'


    def submit_assert_right(self,mark_content):
        '''这个是用来断言正向的'''
        time.sleep(1)
        res_ele = self.driver.find_element('xpath','/html/body/div[1]/section/section/main/div/div[2]/div/div/div/div/div/div/div/table/tbody/tr[1]/td[3]')
        mysql = OperateMysql('cloud')
        res_data = mysql.selectData(f'select username from user where username = {mark_content}')
        assert res_ele.text == mark_content and res_data,'测试失败'



